package com.lanou.tipsy.adapter.songList;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou.tipsy.R;
import com.lanou.tipsy.entity.songList.SongListSpecific.Songs;
import com.lanou.tipsy.tools.volley.VolleySingleton;

import java.util.ArrayList;

/**
 * Created by dllo on 15/10/23.
 *  V Z V
 *  歌单  具体歌曲 适配器
 */
public class SongsListsContentAdpater extends RecyclerView.Adapter<SongsListsContentAdpater.MyViewHolder> {
    public static final String TAG = "SongsListsContentAdpater";
    private ArrayList<Songs> data;
    private LayoutInflater mInflater;
    private VolleySingleton volleySingleton;
    private Context context;


    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public SongsListsContentAdpater(Context context,ArrayList<Songs> data){
        mInflater = LayoutInflater.from(context);
        this.data = data;
//        volleySingleton = VolleySingleton.getInstance();
//        imageLoader = volleySingleton.getImageLoader();
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        if (data != null && data.size() > 0 ){
            ViewGroup.LayoutParams lp = holder.linearLayout.getLayoutParams();
            holder.linearLayout.setLayoutParams(lp);
            holder.singer_name.setText(data.get(position).getAlbumName());
            holder.song_name.setText(data.get(position).getName());

                holder.number.setText("" + (position + 1));

        }if (mOnItemClickLitener != null){
            holder.linearLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.linearLayout,pos);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size() > 0 && data != null ? data.size() : 0;
    }
    class MyViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout linearLayout;
        private TextView number,singer_name,song_name;
        public MyViewHolder(View view){
            super(view);
            linearLayout = (LinearLayout) view.findViewById(R.id.item_fr_songs_list_content);
            number = (TextView) view.findViewById(R.id.tv_songs_list_content_number);
            singer_name = (TextView) view.findViewById(R.id.tv_songs_list_content_singer_name);
            song_name = (TextView) view.findViewById(R.id.tv_songs_list_content_songs_name);
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(mInflater.inflate(
                R.layout.list_fr_songs_lists_content, parent, false));
        return holder;
    }
}
